/**
 * 
 */
package com.nari.interfaces.action;

import java.util.Date;
import java.util.List;

import org.apache.struts2.json.JSONUtil;
import org.apache.struts2.json.annotations.JSON;

import com.nari.baseinfo.model.IBuilding;
import com.nari.baseinfo.model.ICommunity;
import com.nari.baseinfo.model.IHeatMeter;
import com.nari.baseinfo.model.IProject;
import com.nari.baseinfo.model.IShareArea;
import com.nari.baseinfo.service.IBuildingService;
import com.nari.baseinfo.service.ICommunityService;
import com.nari.baseinfo.service.IHeatMeterService;
import com.nari.baseinfo.service.IProjectService;
import com.nari.baseinfo.service.IShareAreaService;
import com.nari.coreframe.action.struts2.JSONActionSupport;
import com.nari.interfaces.model.IHeatMeterData24Gather;
import com.nari.interfaces.service.IHeatMeterData24GatherService;
import com.nari.interfaces.utils.queryvo.HeatMeterData24RealtimeStatis;
import com.nari.platform.model.PageCond;
import com.nari.platform.model.ResultWithPageCond;
import com.nari.platform.utils.CommercialHighPrecisionArith;
import com.opensymphony.xwork2.Action;

/**
 * 
 * @author Xiaopeng
 * @date 2015-1-22
 */
public class HeatMeterData24GatherAction extends JSONActionSupport {
	private static final long serialVersionUID = -1779304942268277094L;
	private IHeatMeterData24GatherService iHeatMeterData24GatherService;
	private IHeatMeterService iHeatMeterService;
	private IProjectService iProjectService;
	private ICommunityService iCommunityService;
	private IBuildingService iBuildingService;
	private IShareAreaService iShareAreaService;
	//分时数据统计查询
	private String meterNo;
	private Date recordTimeStart;
	private Date recordTimeEnd;
	//分页查询
	private int pageIndex = 1; //默认查询第一页列表
	private PageCond pageCond;
	private int pageSize;
	private ResultWithPageCond<HeatMeterData24RealtimeStatis> meterDataStatisPage;
	//分时数据信息维护
	private Date recordTime;
	private HeatMeterData24RealtimeStatis meterDataStatis;
	private IHeatMeter heatMeter;
	private IProject project;
	private ICommunity community;
	private IBuilding building;
	private IShareArea shareArea;
	private List<IHeatMeterData24Gather> meterDataList4Statis;
	
	/**
	 * 分页查询分时热表数据的统计列表
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2015-1-22
	 */
	public String queryMeterDataRealtimeStatisPage() throws Exception {
		//分页信息
		this.pageCond = new PageCond();
		int start = (this.pageIndex - 1) * this.pageCond.getLimit();
		this.pageCond.setStart(start);
		//设置查询的抄表日期，遵循就近一致原则
		if(this.recordTimeStart==null && this.recordTimeEnd==null) {
			this.recordTimeStart = this.recordTimeEnd = new Date();
		}
		if(this.recordTimeStart!=null && this.recordTimeEnd==null) {
			this.recordTimeEnd = this.recordTimeStart;
		}
		if(this.recordTimeStart==null && this.recordTimeEnd!=null) {
			this.recordTimeStart = this.recordTimeEnd;
		}
		//分页结果
		this.meterDataStatisPage = iHeatMeterData24GatherService.queryMeterDataStatis(meterNo, 
				recordTimeStart, recordTimeEnd, pageCond);
		//计算结果集的页数
		this.pageSize = CommercialHighPrecisionArith.divide2Integer4Up(this.meterDataStatisPage.getPageCond().getTotal(), 
				this.meterDataStatisPage.getPageCond().getLimit());
		return "realtimeStatisPage";
	}
	
	/**
	 * 查询分时热表数据的统计详细信息
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2015-1-22
	 */
	public String queryMeterDataStatisDetail() throws Exception {
		//热量表
		this.heatMeter = this.iHeatMeterService.queryMeterByMeterNo(meterNo);
		if(heatMeter != null) {
			//所属项目
			this.project = iProjectService.queryEntityById(heatMeter.getProjectID());
			//所属小区
			this.community = iCommunityService.queryEntityById(heatMeter.getCommunityID());
			//所属楼栋
			if(heatMeter.getBuildingID()!=null && !"".equals(heatMeter.getBuildingID())) {
				this.building = iBuildingService.queryEntityById(heatMeter.getBuildingID());
			}
			//所属分摊区域
			if(heatMeter.getShareAreaID()!=null && !"".equals(heatMeter.getShareAreaID())) {
				this.shareArea = iShareAreaService.queryEntityById(heatMeter.getShareAreaID());
			}
		}
		//热量表数据的分时统计
		this.meterDataStatis = iHeatMeterData24GatherService.queryMeterDataStatisDetail(meterNo, recordTime);
		return "meterDataStatisDetail";
	}
	
	/**
	 * 按统计批次查询热量表分时数据列表
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2015-1-22
	 */
	public String queryMeterDataList4Statis() throws Exception {
		this.meterDataList4Statis = iHeatMeterData24GatherService.queryMeterDataList4Statis(meterNo, recordTime);
		return "meterDataList4Statis";
	}
	
	/**
	 * 按统计批次删除热量表分时数据
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2015-1-22
	 */
	public String deleteMeterDataStatis() throws Exception {
		this.rmsg = iHeatMeterData24GatherService.deleteMeterDataStatis(meterNo, recordTime);
		this.writeJsonStrToResponse(JSONUtil.serialize(rmsg));
		return Action.SUCCESS;
	}
	
	/**
	 * @return the iHeatMeterData24GatherService
	 */
	@JSON(serialize=false)
	public IHeatMeterData24GatherService getiHeatMeterData24GatherService() {
		return iHeatMeterData24GatherService;
	}

	/**
	 * @param iHeatMeterData24GatherService the iHeatMeterData24GatherService to set
	 */
	public void setiHeatMeterData24GatherService(
			IHeatMeterData24GatherService iHeatMeterData24GatherService) {
		this.iHeatMeterData24GatherService = iHeatMeterData24GatherService;
	}

	/**
	 * @return the iHeatMeterService
	 */
	@JSON(serialize=false)
	public IHeatMeterService getiHeatMeterService() {
		return iHeatMeterService;
	}

	/**
	 * @param iHeatMeterService the iHeatMeterService to set
	 */
	public void setiHeatMeterService(IHeatMeterService iHeatMeterService) {
		this.iHeatMeterService = iHeatMeterService;
	}

	/**
	 * @return the iProjectService
	 */
	@JSON(serialize=false)
	public IProjectService getiProjectService() {
		return iProjectService;
	}

	/**
	 * @param iProjectService the iProjectService to set
	 */
	public void setiProjectService(IProjectService iProjectService) {
		this.iProjectService = iProjectService;
	}

	/**
	 * @return the iCommunityService
	 */
	@JSON(serialize=false)
	public ICommunityService getiCommunityService() {
		return iCommunityService;
	}

	/**
	 * @param iCommunityService the iCommunityService to set
	 */
	public void setiCommunityService(ICommunityService iCommunityService) {
		this.iCommunityService = iCommunityService;
	}

	/**
	 * @return the iBuildingService
	 */
	@JSON(serialize=false)
	public IBuildingService getiBuildingService() {
		return iBuildingService;
	}

	/**
	 * @param iBuildingService the iBuildingService to set
	 */
	public void setiBuildingService(IBuildingService iBuildingService) {
		this.iBuildingService = iBuildingService;
	}

	/**
	 * @return the iShareAreaService
	 */
	@JSON(serialize=false)
	public IShareAreaService getiShareAreaService() {
		return iShareAreaService;
	}

	/**
	 * @param iShareAreaService the iShareAreaService to set
	 */
	public void setiShareAreaService(IShareAreaService iShareAreaService) {
		this.iShareAreaService = iShareAreaService;
	}

	/**
	 * @return the meterNo
	 */
	public String getMeterNo() {
		return meterNo;
	}

	/**
	 * @param meterNo the meterNo to set
	 */
	public void setMeterNo(String meterNo) {
		this.meterNo = meterNo;
	}

	/**
	 * @return the recordTimeStart
	 */
	public Date getRecordTimeStart() {
		return recordTimeStart;
	}

	/**
	 * @param recordTimeStart the recordTimeStart to set
	 */
	public void setRecordTimeStart(Date recordTimeStart) {
		this.recordTimeStart = recordTimeStart;
	}

	/**
	 * @return the recordTimeEnd
	 */
	public Date getRecordTimeEnd() {
		return recordTimeEnd;
	}

	/**
	 * @param recordTimeEnd the recordTimeEnd to set
	 */
	public void setRecordTimeEnd(Date recordTimeEnd) {
		this.recordTimeEnd = recordTimeEnd;
	}

	/**
	 * @return the pageIndex
	 */
	public int getPageIndex() {
		return pageIndex;
	}

	/**
	 * @param pageIndex the pageIndex to set
	 */
	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	/**
	 * @return the pageCond
	 */
	public PageCond getPageCond() {
		return pageCond;
	}

	/**
	 * @param pageCond the pageCond to set
	 */
	public void setPageCond(PageCond pageCond) {
		this.pageCond = pageCond;
	}

	/**
	 * @return the pageSize
	 */
	public int getPageSize() {
		return pageSize;
	}

	/**
	 * @param pageSize the pageSize to set
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * @return the meterDataStatisPage
	 */
	public ResultWithPageCond<HeatMeterData24RealtimeStatis> getMeterDataStatisPage() {
		return meterDataStatisPage;
	}

	/**
	 * @param meterDataStatisPage the meterDataStatisPage to set
	 */
	public void setMeterDataStatisPage(
			ResultWithPageCond<HeatMeterData24RealtimeStatis> meterDataStatisPage) {
		this.meterDataStatisPage = meterDataStatisPage;
	}

	/**
	 * @return the recordTime
	 */
	public Date getRecordTime() {
		return recordTime;
	}

	/**
	 * @param recordTime the recordTime to set
	 */
	public void setRecordTime(Date recordTime) {
		this.recordTime = recordTime;
	}

	/**
	 * @return the meterDataStatis
	 */
	public HeatMeterData24RealtimeStatis getMeterDataStatis() {
		return meterDataStatis;
	}

	/**
	 * @param meterDataStatis the meterDataStatis to set
	 */
	public void setMeterDataStatis(HeatMeterData24RealtimeStatis meterDataStatis) {
		this.meterDataStatis = meterDataStatis;
	}

	/**
	 * @return the heatMeter
	 */
	public IHeatMeter getHeatMeter() {
		return heatMeter;
	}

	/**
	 * @param heatMeter the heatMeter to set
	 */
	public void setHeatMeter(IHeatMeter heatMeter) {
		this.heatMeter = heatMeter;
	}

	/**
	 * @return the project
	 */
	public IProject getProject() {
		return project;
	}

	/**
	 * @param project the project to set
	 */
	public void setProject(IProject project) {
		this.project = project;
	}

	/**
	 * @return the community
	 */
	public ICommunity getCommunity() {
		return community;
	}

	/**
	 * @param community the community to set
	 */
	public void setCommunity(ICommunity community) {
		this.community = community;
	}

	/**
	 * @return the building
	 */
	public IBuilding getBuilding() {
		return building;
	}

	/**
	 * @param building the building to set
	 */
	public void setBuilding(IBuilding building) {
		this.building = building;
	}

	/**
	 * @return the shareArea
	 */
	public IShareArea getShareArea() {
		return shareArea;
	}

	/**
	 * @param shareArea the shareArea to set
	 */
	public void setShareArea(IShareArea shareArea) {
		this.shareArea = shareArea;
	}

	/**
	 * @return the meterDataList4Statis
	 */
	public List<IHeatMeterData24Gather> getMeterDataList4Statis() {
		return meterDataList4Statis;
	}

	/**
	 * @param meterDataList4Statis the meterDataList4Statis to set
	 */
	public void setMeterDataList4Statis(
			List<IHeatMeterData24Gather> meterDataList4Statis) {
		this.meterDataList4Statis = meterDataList4Statis;
	}

}
